package com.jinlejia.erp.adapter;

import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.RecyclerView;

import com.freedom.yefeng.yfrecyclerview.YfListAdapter;
import com.freedom.yefeng.yfrecyclerview.YfSimpleViewHolder;
import com.jinlejia.erp.R;
import com.jinlejia.erp.databinding.ItemSearchHouseResultBinding;

import java.util.ArrayList;


/**
 * 房源客源结果Adapter
 * Created by Administrator on 2017/4/27 0027.
 */

public class SearchCustomerAdapter extends YfListAdapter<String> {

    private String word;

    public SearchCustomerAdapter(ArrayList<String> data, String keyWord) {
        super(data);
        this.word = keyWord;
    }
    public void setWord( String w ){
        this.word = w;
    }

    @Override
    public RecyclerView.ViewHolder onCreateDataViewHolder(ViewGroup parent) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_search_house_result, parent, false);
        //搜索结果
        return new ResultViewHolder(view);
    }

    @Override
    public RecyclerView.ViewHolder onCreateEmptyViewHolder(ViewGroup parent) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.empty_layout, parent, false);

        return new YfSimpleViewHolder(view);
    }

    @Override
    public void onBindDataViewHolder(RecyclerView.ViewHolder holder, int position) {
        String tmp = "<font color=\"red\">" + word + "</font>";
        String str =  mData.get(position).replace(word, tmp);
        ItemSearchHouseResultBinding binding = DataBindingUtil.getBinding(holder.itemView);
        binding.tvHouseName.setText(Html.fromHtml(str));
        binding.getRoot().setTag(mData.get(position));
    }

    static final class ResultViewHolder extends RecyclerView.ViewHolder {

        public ResultViewHolder(View itemView) {
            super(itemView);
            ItemSearchHouseResultBinding binding =DataBindingUtil.bind(itemView);
            binding.tvHouseArea.setVisibility(View.GONE);
        }
    }

}
